/**
 * @param type  
 * 1000 初始化连接
 * 1001 发起语音通话请求
 * 1002 发起视频通话请求
 * 1003 退出登录,清除缓存
 * 1004 版本升级,清除缓存
 * 1005 链接跳转
 * 1006 打开文件
 * 1007 下载文件
 */


// 初始化连接
export const initInterface = (token) => {
	try {
		console.log(`{"type":1000,"token": "${token}"},`, '初始化连接');
		javascript: olImInterface.navigateTo(`{"type":1000,"token": "${token}"}`)
	} catch (e) {
		console.log('初始化连接报错', e);
		//TODO handle the exception
	}
}

// 发起语音通话请求
export const voiceCallRequest = (targetId) => {
	try {
		console.log(`{"type":1001,"targetId":"${targetId}"}`, '发起语音通话请求');
		javascript: olImInterface.navigateTo(`{"type":1001,"targetId":"${targetId}"}`)
	} catch (e) {
		console.log('发起语音通话请求', e);
		//TODO handle the exception
	}
}

// 发起视频通话请求
export const videoCallRequest = (targetId) => {
	try {
		console.log(`{"type":1002,"targetId":"${targetId}"}`, '视频通话请求');
		javascript: olImInterface.navigateTo(`{"type":1002,"targetId":"${targetId}"}`)
	} catch (e) {
		console.log('视频通话请求', e);
		//TODO handle the exception
	}
}

// 退出登录,清楚缓存
export const logoutInterface = () => {
	try {
		javascript: olImInterface.navigateTo(`{"type":1003}`)
	}
	catch (e) {
		console.log('退出登录,清楚缓存报错', e);
		//TODO handle the exception
	}
}

// 升级版本,清除缓存
export const updateInterface = (url) => {
	try {
		console.log('升级版本,清除缓存', `{"type":1004,"url":"${url}"}`);
		javascript: olImInterface.navigateTo(`{"type":1004,"url":"${url}"}`)
	}
	catch (e) {
		console.log('升级版本,清除缓存报错', e);
		//TODO handle the exception
	}
}

// 点击跳转链接link
export const openWebViewLink = (url) => {
	try {
		javascript:olImInterface.navigateTo(`{"type":1005,"url":"${url}"}`)
	}
	catch (e) {
		console.log('跳转链接link, 报错: ', e);
		//TODO handle the exception
	}
}

// 打开文件
export const openWebViewFlie = (url) => {
	try {
		javascript:olImInterface.navigateTo(`{"type":1006,"url":"${url}"}`)
	}
	catch (e) {
		console.log('打开文件, 报错: ', e);
		//TODO handle the exception
	}
}

// 下载文件
export const downloadWebViewFlie = (url, fileName) => {
	try {
		javascript:olImInterface.navigateTo(`{"type":1007,"url":"${url}","fileName":"${fileName}"}`)
	}
	catch (e) {
		console.log('下载文件, 报错: ', e);
		//TODO handle the exception
	}
}

// 切换语言
export const changeLang = (url, fileName) => {
	try {
			console.log(`切换语言：{"type":1008,"lang": "${uni.getLocale()}"}`);
		javascript:olImInterface.navigateTo(`{"type":1008,"lang": "${uni.getLocale()}"}`)
	}
	catch (e) {
		console.log('切换语言, 报错: ', e);
		//TODO handle the exception
	}
}